﻿using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Badger.Vhdl;
using Weazel.Badger.Vhdl.Types;

namespace Weazel.Badger
{
	public class RegisterEntity : 
		Vhdl.Entity
	{
		private Vhdl.Port clockPort;
		public Vhdl.Port ClockPort
		{
			get { return clockPort; }
			protected set { this.clockPort = value; }
		}

		private Vhdl.Port resetPort;
		public Vhdl.Port ResetPort
		{
			get { return resetPort; }
			protected set { this.resetPort = value; }
		}

		private Dictionary<string, VhdlRegister> registers =
			new Dictionary<string, VhdlRegister>();

		public Dictionary<string, VhdlRegister> Registers
		{
			get
			{
				return registers;
			}

			set
			{
				registers = value;
			}
		}

		public bool IsRegister(Vhdl.Signal signal)
		{
			foreach (VhdlRegister r in registers.Values)
				if (r.WriteSignal == signal)
					return true;

			return false;
		}

		public VhdlRegister CreateRegister(string name, Weazel.Badger.Vhdl.Types.Type type)
		{
			VhdlRegister reg = new VhdlRegister(this, type, null, name);
			registers.Add(name, reg);
			return reg;
		}

		public RegisterEntity(string name) 
			: base(name)
		{
		}
	}
}
